package com.example.todolist.controller;

import com.example.todolist.entity.TodoItem;
import com.example.todolist.service.TodoItemService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api")
@Slf4j
@Api(tags = "Todo List API")
public class TodoItemController {
    @Autowired
    private TodoItemService todoItemService;

    @ApiOperation("查询所有待办事项")
    @GetMapping("/get-todo")
    public List<TodoItem> getAll() {
        log.info("查询所有待办事项");
        return todoItemService.getAll();
    }

    @ApiOperation("添加新的待办事项")
    @PostMapping("/add-todo")
    public TodoItem addTodo(@RequestBody TodoItem todoItem) {
        log.info("添加待办事项: {}", todoItem.getValue());
        return todoItemService.addTodo(todoItem);
    }

    @ApiOperation("更新待办事项状态")
    @PostMapping("/update-todo/{id}")
    public TodoItem updateIsCompleted(@PathVariable Long id) {
        log.info("更新待办事项状态, id={}", id);
        return todoItemService.updateIsCompleted(id);
    }

    @ApiOperation("删除待办事项")
    @PostMapping("/del-todo/{id}")
    public boolean deleteById(@PathVariable Long id) {
        log.info("删除待办事项, id={}", id);
        return todoItemService.deleteById(id);
    }
} 